//https://leetcode.cn/problems/valid-sudoku/
class Solution {
    boolean[][] colCheck;// 列
    boolean[][] rowCheck;// 行
    boolean[][][] grid;

    public boolean isValidSudoku(char[][] board) {
        colCheck = new boolean[9][10];
        rowCheck = new boolean[9][10];
        grid = new boolean[3][3][10];

        for (int i = 0; i < 9; i++) {
            for (int j = 0; j < 9; j++) {
                if (board[i][j] != '.') {
                    //判断是否有效
                    int val = board[i][j] - '0';
                    int row = i / 3;
                    int col = j / 3;
                    if (rowCheck[i][val] || colCheck[j][val] || grid[row][col][val]) {
                        return false;
                    }
                    rowCheck[i][val] = colCheck[j][val] = grid[row][col][val] = true;
                }
            }
        }
        return true;
    }
}